# == Schema Information
#
# Table name: radacct
#
#  radacctid            :integer          default(0), not null
#  acctsessionid        :string(64)       default(""), not null
#  acctuniqueid         :string(32)       default(""), not null
#  username             :string(64)       default(""), not null
#  groupname            :string(64)       default(""), not null
#  realm                :string(64)       default("")
#  nasipaddress         :string(15)       default(""), not null
#  nasportid            :string(15)
#  nasporttype          :string(32)
#  acctstarttime        :datetime
#  acctstoptime         :datetime
#  acctsessiontime      :integer
#  acctauthentic        :string(32)
#  connectinfo_start    :string(50)
#  connectinfo_stop     :string(50)
#  acctinputoctets      :integer
#  acctoutputoctets     :integer
#  calledstationid      :string(50)       default(""), not null
#  callingstationid     :string(50)       default(""), not null
#  acctterminatecause   :string(32)       default(""), not null
#  servicetype          :string(32)
#  framedprotocol       :string(32)
#  framedipaddress      :string(15)       default(""), not null
#  acctstartdelay       :integer
#  acctstopdelay        :integer
#  xascendsessionsvrkey :string(10)
#

class Radacct < ActiveRecord::Base
	self.table_name = "radacct"
  belongs_to :user, :primary_key => :username, :foreign_key => :username

  scope :online_users, -> {where(:acctstoptime => nil)}

  def hotspot_name
    Hotspot.find_by(:mac => self.calledstationid).try(:name)
  end
end
